﻿using System;
using NUnit.Framework;

namespace PropertyExpression.TypedSqlBuilder.Test
{
    [TestFixture]
    public class SqlTest2
    {
        [Test]
        public void Test4()
        {
            var query = NewMethod1("", "", DateTime.Now, DateTime.Now);
            Console.WriteLine(query);
        }

        private static IInnerJoin<SalesOrderHeaderProjection> NewMethod1(
            string productName, string contactFirstName, 
            DateTime startOrderDate, DateTime endOrderDate)
        {
            return
                from salesOrderHeader in Schema.SalesOrderHeaders
                from salesOrderDetail in Schema.SalesOrderDetails.InnerJoin() select 
                    salesOrderHeader.SalesOrderID().Equal(salesOrderDetail.SalesOrderID()).To(
                from specialOfferProduct in Schema.SpecialOfferProducts.InnerJoin() select 
                    salesOrderDetail.SpecialOfferID().Equal(specialOfferProduct.SpecialOfferID()).And(
                    salesOrderDetail.ProductID().Equal(specialOfferProduct.ProductID())).To(
                from specialOffer in Schema.SpecialOffers.InnerJoin() select 
                    specialOfferProduct.SpecialOfferID().Equal(specialOffer.SpecialOfferID()).To(
                from product in Schema.Products.InnerJoin() select 
                    specialOfferProduct.ProductID().Equal(product.ProductID()).To(
                from individual in Schema.Individuals.LeftOuterJoin() select
                    salesOrderHeader.CustomerID().Equal(individual.CustomerID()).To(
                from contact in Schema.Contacts.LeftOuterJoin() select
                    individual.ContactID().Equal(contact.ContactID()).To(
                    product.Name().Like(productName.Const()).And(
                    contact.FirstName().Like(contactFirstName.Const())).And(
                    salesOrderHeader.OrderDate().Between(startOrderDate.Const(), endOrderDate.Const())).Where(),
                    Query.Select<SalesOrderHeaderProjection>()
                        .OrderDate(salesOrderHeader.OrderDate())
                ))))));
        }
    }
}
